const WebSocketServer = require('ws').Server,
    wss = new WebSocketServer({ port: 3001, origin: 'Sec-WebSocket-Origin:*' });

wss.on('connection', function (ws) {
    console.log('服务端：客户端已连接');
    ws.on('message', function (message) {
        //打印客户端监听的消息
        console.log(message);
        ws.send('Hello message');
    });
    ws.on('open', function () {
        ws.send('Hello open');
    });

    ws.on('ping', function () {
        console.log('disconnected');
    });

    ws.on('error', function () {
        console.log('disconnected');
    });

    ws.on('close', function () {
        console.log('disconnected');
    });

});

